package com.edu.exam.enums.exam;

import com.edu.exam.enums.core.StatusEnum;

/**
 * 答题状态枚举
 * 管理学生答题过程的状态
 *
 * @author System
 * @version 1.0.0
 */
public enum AnswerStatus implements StatusEnum {

    NOT_STARTED("NOT_STARTED", "未开始", 1),
    IN_PROGRESS("IN_PROGRESS", "答题中", 2),
    COMPLETED("COMPLETED", "已完成", 3),
    MODIFIED("MODIFIED", "已修改", 4),
    FLAGGED("FLAGGED", "已标记", 5),
    REVIEWED("REVIEWED", "已审阅", 6),
    FINAL("FINAL", "终稿", 7);

    private final String code;
    private final String description;
    private final int order;

    AnswerStatus(String code, String description, int order) {
        this.code = code;
        this.description = description;
        this.order = order;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public int getOrder() {
        return order;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static AnswerStatus fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Answer status code cannot be null or empty");
        }

        for (AnswerStatus value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        throw new IllegalArgumentException("Unknown answer status code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值，null如果未找到
     */
    public static AnswerStatus fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            return null;
        }

        for (AnswerStatus value : values()) {
            if (value.getDescription().equals(description)) {
                return value;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}